package com.bpc.cs.managed.model;

import java.util.List;

import javax.faces.model.ListDataModel;

import org.primefaces.model.SelectableDataModel;

import com.bpc.cs.managed.dvo.SchemeDVO;

/**
 * @author   phan_tp
 * @datetime Dec 5, 2012 : 3:37:00 PM
 */
public class SchemeDataModel extends ListDataModel<SchemeDVO> implements SelectableDataModel<SchemeDVO> {

	public SchemeDataModel(List<SchemeDVO> listSchemeDVO) {
		super(listSchemeDVO);
	}

	/**
	 * Get object which is selected at client
	 * @param String rowKey
	 */
	@SuppressWarnings("unchecked")
	@Override
	public SchemeDVO getRowData(String rowKey) {
		List<SchemeDVO> listSchemeDVO = (List<SchemeDVO>) getWrappedData();
		for (SchemeDVO schemeDVO : listSchemeDVO) {
			if (schemeDVO.getSchemeID() == Integer.parseInt(rowKey)) {
				return schemeDVO;
			}
		}
		return null;
	}

	/**
	 * Get key of selected row which is selected at client
	 * @param SchemeDTO schemeDTO
	 */
	@Override
	public Object getRowKey(SchemeDVO schemeDVO) {
		return schemeDVO.getSchemeID();
	}
}
